package com.javasm.service.impl;

import com.javasm.dao.OrderCommentDao;
import com.javasm.entity.OrderComment;
import com.javasm.service.OrderCommentService;
import com.javasm.utils.MyBatisHeapler;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class OrderCommentServiceImpl implements OrderCommentService {
    @Override
    public List<OrderComment> listComments(OrderComment inputComment, Integer page, Integer pageSize, String sort) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        OrderCommentDao mapper = sqlSession.getMapper(OrderCommentDao.class);
        List<OrderComment> orderComments = mapper.listComments(inputComment, (page - 1) * pageSize, pageSize, sort);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return orderComments;
    }

    @Override
    public Integer countComments(OrderComment inputComment) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        OrderCommentDao mapper = sqlSession.getMapper(OrderCommentDao.class);
        Integer count = mapper.countComments(inputComment);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return count;
    }

    @Override
    public List<OrderComment> listAllComments(OrderComment inputComment, Integer page, Integer pageSize, String sort) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        OrderCommentDao mapper = sqlSession.getMapper(OrderCommentDao.class);
        List<OrderComment> orderComments = mapper.listAllComments(inputComment, (page - 1) * pageSize, pageSize, sort);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return orderComments;
    }

    @Override
    public Integer countAllComments(OrderComment inputComment) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        OrderCommentDao mapper = sqlSession.getMapper(OrderCommentDao.class);
        Integer count = mapper.countAllComments(inputComment);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return count;
    }

    @Override
    public Integer editCommentStatus(OrderComment inputComment) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        OrderCommentDao mapper = sqlSession.getMapper(OrderCommentDao.class);
        Integer resNum = mapper.editCommentStatus(inputComment);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return resNum;
    }

    @Override
    public Integer deleteComment(OrderComment inputComment) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        OrderCommentDao mapper = sqlSession.getMapper(OrderCommentDao.class);
        Integer resNum = mapper.deleteComment(inputComment);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return resNum;
    }
}
